package yxy.game.pm2.chat.module;

import yxy.cherry.data.DataCenter;
import yxy.cherry.data.bean.regiondate;
import yxy.game.pm2.bean.PlayerBean;
import yxy.game.pm2.bean.area.ChatChannelType;

/** 同省频道 */
public class ChatChannel_HomeTown extends BaseChatChannelModule {

	private int townId;

	private int clusterId; //专服id

	public void setTownId(int townId) {
		this.townId = townId;
	}

	public int getTownId() {
		return townId;
	}

	public int getClusterId() {
		return clusterId;
	}

	public void setClusterId(int clusterId) {
		this.clusterId = clusterId;
	}

	public ChatChannel_HomeTown(int clusterId, int townId) {
		setClusterId(clusterId);
		setTownId(townId);
	}

	@Override
	protected int historySize() {
		return 20;
	}

	@Override
	protected ChatChannelType getChannelType() {
		return ChatChannelType.CHAT_REGION;
	}

	@Override
	protected String key() {
		return String.format("CHAT:TOWN:%s:%s:MSG", getClusterId(), getTownId());
	}

	@Override
	protected String keySub() {
		return String.format("CHAT:TOWN:%s:%s:SUB", getClusterId(), getTownId());
	}

	public static ChatChannel_HomeTown get(int clusterId, PlayerBean playerBean) {
		if (playerBean == null) {
			return null;
		}
		regiondate _regiondate = DataCenter.getData(playerBean.getTown(), regiondate.class);
		if (_regiondate == null) {
			return null;
		}
		return new ChatChannel_HomeTown(clusterId, _regiondate.getId());
	}

	public static ChatChannel_HomeTown get(int clusterId, int regionId) {
		regiondate _regiondate = DataCenter.getData(regionId, regiondate.class);
		if (_regiondate == null) {
			return null;
		}
		return new ChatChannel_HomeTown(clusterId, _regiondate.getId());
	}

}
